---
const response = await fetch("http://localhost:9901/api/getUser");
const data = await response.json();
---

<head>
  <script> 
  import swal from 'sweetalert';
  swal;
</script>

</head>
<div class="container">
  <div class="card">
    <p class="name">{data.nickName}</p>
    <p class="info email" data-email={data.email}>
      邮箱：{data.email}
      <a href=`mailto:${data.email}` id="emailButton" class="button">&#9993;</a>
      <span id="emailButton" class="button" onclick="copyFunEmail();">&#128203;</span>
    </p>

    <p class="info phone" data-phone={data.phone}>
      电话：{data.phone}
      <!-- <a >+123456789</a> -->
      <a href=`tel:${data.phone}` id="phoneButton" class="button">&#128222;</a>
      <span id="phoneButton" class = "button" onclick = "copyFunPhone()">&#128203;</span>
    </p>
  </div>
</div>

<script is:inline>
function copyFunEmail() {
    const emailElement = document.querySelector(".info.email");
    const email = emailElement.dataset.email; // 设置要复制的邮箱
    navigator.clipboard
        .writeText(email)
        .then(() => {
            swal({
                title: "复制成功",
                text: email,
                icon: "success",
                buttons: false,
                timer: 1000,
            });
        })
        .catch((error) => { });
}

function copyFunPhone() {
    const phoneNumberElement = document.querySelector(".info.phone");
    const phoneNumber = phoneNumberElement.dataset.phone; // 设置要复制的电话号码
    navigator.clipboard
        .writeText(phoneNumber)
        .then(() => {
            swal({
                title: "复制成功",
                text: phoneNumber,
                icon: "success",
                buttons: false,
                timer: 1000,
            });
        })
        .catch((error) => { });
}
</script>

<style>
  .container {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .card {
    background-color: #d9fdfb;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 20px;
    width: 60%;
    transition: transform 0.3s, box-shadow 0.3s;
    text-align: center;
  }

  .card:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }

  .name {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
  }

  .info {
    margin-bottom: 20px;
  }

  .email,
  .phone {
    color: #666;
  }

  .button {
    display: none;
    cursor: pointer;
  }

  p:hover {
    color: rgb(248, 69, 4);
  }

  p:hover .button {
    display: inline;
  }
</style>
